wayland: Don't hardcode /tmp
authorMatthias Clasen <mclasen@redhat.com>
Fri, 22 Jan 2016 03:53:06 +0000 (22:53 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 22 Jan 2016 03:57:39 +0000 (22:57 -0500)
As pointed out in https://bugzilla.gnome.org/show_bug.cgi?id=760964,
we should use the GLib facilities for determining the preferred
location for temporary files.

gdk/wayland/gdkdisplay-wayland.c

index 7c19a5c6cba1b07843d6b947293beddc3b11fd7d..5e88d966ad612949a47bd6ac28e21f0b8209330c 100644 (file)
@@ -928,24 +928,27 @@ create_shm_pool (struct wl_shm  *shm,
                  size_t         *buf_length,
                  void          **data_out)
 {
-  char filename[] = "/tmp/wayland-shm-XXXXXX";
+  char *filename;
   struct wl_shm_pool *pool;
   int fd;
   void *data;
 
+  filename = g_strconcat (g_get_tmp_dir (), G_DIR_SEPARATOR_S, "wayland-shm-XXXXXX", NULL);
   fd = mkstemp (filename);
   if (fd < 0)
     {
       g_critical (G_STRLOC ": Unable to create temporary file (%s): %s",
                   filename, g_strerror (errno));
+      g_free (filename);
       return NULL;
     }
   unlink (filename);
 
   if (ftruncate (fd, size) < 0)
     {
-      g_critical (G_STRLOC ": Truncating temporary file failed: %s",
-                  g_strerror (errno));
+      g_critical (G_STRLOC ": Truncating temporary file (%s) failed: %s",
+                  filename, g_strerror (errno));
+      g_free (filename);
       close (fd);
       return NULL;
     }
@@ -954,8 +957,9 @@ create_shm_pool (struct wl_shm  *shm,
 
   if (data == MAP_FAILED)
     {
-      g_critical (G_STRLOC ": mmap'ping temporary file failed: %s",
-                  g_strerror (errno));
+      g_critical (G_STRLOC ": mmap'ping temporary file (%s) failed: %s",
+                  filename, g_strerror (errno));
+      g_free (filename);
       close (fd);
       return NULL;
     }
@@ -963,6 +967,7 @@ create_shm_pool (struct wl_shm  *shm,
   pool = wl_shm_create_pool (shm, fd, size);
 
   close (fd);
+  g_free (filename);
 
   *data_out = data;
   *buf_length = size;